<template>
  <div class="wode">
    <div class="user-info">
      <div class="user-img">
        <img src="/user.jpg" alt="">
      </div>
      <div class="user-desc">
        <p class="user-name">宇宙无敌大大怪 <span class="logout" @click="userLogout">点击退出</span></p>
        <p class="user-id">fourth-mall账号: {{username}}</p>
        <a href="#/home/address" class="user-addr">我的收货地址 +</a>
      </div>
    </div>
    <div class="user-order">
      <div class="o-hd">
        <h4>我的订单</h4>
        <a href="#/home/allOrder" class="allOrder">全部</a>
      </div>
      <div class="o-bd">
        <a href="#/home/payment">
          <dl>
            <dt>
              <van-icon name="paid" :info="unfinishedOrder" />
            </dt>
            <dd>待付款</dd>
          </dl>
        </a>
        <a href="#/home/undeliver">
          <dl>
            <dt>
              <van-icon name="todo-list-o" :info="finishedOrder" />
            </dt>
            <dd>待发货</dd>
          </dl>
        </a>
        <a href="">
          <dl>
            <dt>
              <van-icon name="logistics" />
            </dt>
            <dd>待收货</dd>
          </dl>
        </a>
        <a href="">
          <dl>
            <dt>
              <van-icon name="chat-o" />
            </dt>
            <dd>待评价</dd>
          </dl>
        </a>
        <a href="">
          <dl>
            <dt>
              <van-icon name="after-sale" />
            </dt>
            <dd>退款/售货</dd>
          </dl>
        </a>
      </div>
    </div>
    <div class="user-order user-tool">
      <div class="o-hd">
        <h4>我的工具</h4>
      </div>
      <div class="o-bd">
        <a href="">
          <dl>
            <dt>
              <van-icon name="service-o" />
            </dt>
            <dd>官方客服</dd>
          </dl>
        </a>
        <a href="">
          <dl>
            <dt>
              <van-icon name="point-gift-o" />
            </dt>
            <dd>试用领取</dd>
          </dl>
        </a>
        <a href="">
          <dl>
            <dt>
              <van-icon name="vip-card-o" />
            </dt>
            <dd>店铺会员</dd>
          </dl>
        </a>
      </div>
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import { Dialog } from 'vant'
// 用户是否退出登录
function beforeClose(action, done) {
  if (action === 'confirm') {
    localStorage.removeItem('token')
    location.reload(true) // 强制刷新
    setTimeout(done, 1000)
  } else {
    done()
  }
}
export default {
  data() {
    return {
      username: JSON.parse(localStorage.user).username
    }
  },
  computed: {
    ...mapGetters({
      unfinishedOrder: 'cart/getUnfinishedOrder',
      finishedOrder: 'cart/getFinishedOrder'
    })
  },
  methods: {
    userLogout() {
      Dialog.confirm({
        title: '退出提示',
        message: '您确认要退出fourth-mall吗?',
        beforeClose
      })
    }
  }
}
</script>
<style lang="scss" >
.wode {
  margin-top: -5px;
  width: 100%;
  min-height: 580px;
  box-sizing: border-box;
  padding: 8px;
  background-color: #f5f5f5;
  > div {
    margin-bottom: 10px;
    width: 100%;
    padding: 12px;
    box-sizing: border-box;
    border-radius: 6px;
    background: #fff;
  }
  .user-info {
    display: flex;
    .user-img {
      width: 80px;
      border-radius: 10px;
      overflow: hidden;
      img {
        width: 100%;
      }
    }
    .user-desc {
      text-indent: 20px;
      line-height: 1.5;
      margin-top: 10px;
      .user-name {
        font-size: 16px;
        .logout {
          padding-left: 20px;
          font-size: 12px;
          color: #888;
        }
      }
      .user-id,
      .user-addr {
        font-size: 14px;
        color: #888;
      }
      .user-addr {
        padding-left: 20px;
        color: #0092ff;
      }
    }
  }
  .user-order {
    > div {
      display: flex;
      justify-content: space-between;
    }
    .o-hd {
      span {
        font-size: 14px;
        color: #999;
      }
      .allOrder {
        font-size: 14px;
      }
    }
    .o-bd {
      margin-top: 12px;
      text-align: center;
      dl {
        margin-top: 10px;
        dt {
          font-size: 20px;
        }
        dd {
          font-size: 14px;
        }
      }
    }
  }
}
</style>